#include "stuinfo.hpp"


void inputstu(stuinfo stu[], int n)
{
    std::cout << "Please input information of " << n << " students:" << std::endl;
    for(int i = 0;i < n; i++)
    {
        std::cout << "Student" << i << "`s name:";
        std::cin >> stu[i].name;
        std::cout << "Student" << i << "`s scores:";
        std::cin >> stu[i].score[0] >> stu[i].score[1] >> stu[i].score[2];
    }
}
void showstu(stuinfo stu[], int n)
{
    std::cout << "The information of " << n << "students you input are: " << std::endl;
    for(int i = 0;i < n; i++)
    {       
        std::cout << "Student " << i << "name:" << stu[i].name << ","\
        << "scores: " << stu[i].score[0] << stu[i].score[1] << stu[i].score[2] << std::endl;
    }
}
void sortstu(stuinfo stu[], int n)
{
    for(int i = 0; i < n - 1; i++)
    {
        for(int j = 0; j < n - i -1; j++)
        {
            if((stu[j].score[0]+stu[j].score[1]+stu[j].score[2])/3 <\
            (stu[j+1].score[0]+stu[j+1].score[1]+stu[j+1].score[2])/3)
            {
                stuinfo tmp;    
                tmp = stu[j];
                stu[j] = stu[j + 1];
                stu[j + 1] = tmp;  
            }
        }
    }
    std::cout << "The descending order of the students: " << std::endl;
    for(int i = 0; i < n; i++)
    {
        std::cout << "student " << i << " name: " << stu[i].name << ", "\
        << "scores: " << stu[i].score[0] << stu[i].score[1] << stu[i].score[2] << " average: "\
        << (stu[i].score[0]+stu[i].score[1]+stu[i].score[2])/3 << std::endl;
    }
}

bool findstu(stuinfo stu[], int n, char ch[])
{
    
    for(int i = 0; i < n; i++)
    {
        if(strcmp(ch, stu[i].name))
        {
            std::cout << ch << "is in the students list." << std::endl;
            return 1;
        }
    }
    std::cout << ch << "is not in the students list." << std::endl;
    return 0;
}
